<template>
  <div class="xiangqingye">
    <el-container>
      <el-aside width="300px">
        <img src="../assets/下载.png" alt />
        <!-- <el-row>
  <button class="btn1"  @click="open2">点击收藏</button>
        </el-row>-->
      </el-aside>
      <el-main>
        <div class="box">
          <el-row v-for="(product,key) in products[0]" :key="key" @click="fangda(key)">
            <el-col :span="8">
              <img :src="getPic(product.productPic)" alt class="imgbox" />
            </el-col>
            <el-col :span="16">
              <div class="font">
                <h3>{{product.productName}}</h3>
                <span>花语：{{product.productMessage}}</span>
                <br />
                <span>覆盖范围：苏州，上海，南京和杭州。</span>
                <br />
                <span>提供当天送货服务：苏州，上海，南京和杭州。</span>
                <br />
                <span>产品类别： 花朵</span>
              </div>
            </el-col>
          </el-row>
        </div>
        <el-table
          ref="multipleTable"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="100"></el-table-column>
          <el-table-column label="颜色" width="150">
            <template slot-scope="scope">{{ scope.row.date }}</template>
          </el-table-column>
          <el-table-column prop="address" label="规格" width="150"></el-table-column>

          <el-table-column prop="name" label="价格" width="0"></el-table-column>
        </el-table>
        <el-row :gutter="25">
          <el-col :span="12">
            <button class="btn" @click="open1">加入购物车</button>
          </el-col>
          <el-col :span="12">
            <button class="btn" @click="open2">
              <i class="el-icon-star-off"></i>收藏
            </button>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
    <img src="../assets/344.jpg" alt class="tu" />
    <el-row :gutter="50">
      <el-col :span="12" :offset="6">
        <span class="title">日子有光，人间美好</span>
      </el-col>
    </el-row>
    <el-row :gutter="150">
      <el-col :span="12" :offset="7">
        <span class="title1">有时候觉得，生活就像一座围墙</span>
      </el-col>
    </el-row>
    <el-row :gutter="150">
      <el-col :span="12" :offset="7">
        <span class="title1">化上妆容精致，与世界短兵相接</span>
      </el-col>
    </el-row>
    <el-row :gutter="150">
      <el-col :span="12" :offset="7">
        <span class="title1">即便在很多个四下无人的夜</span>
      </el-col>
    </el-row>
    <el-row :gutter="150">
      <el-col :span="12" :offset="7">
        <span class="title1">也会想要，就随心所欲地做自己吧</span>
      </el-col>
    </el-row>
    <el-row :gutter="150">
      <el-col :span="12" :offset="7">
        <span class="title1">自由的，洒脱的，不受约束的</span>
      </el-col>
    </el-row>
    <el-row :gutter="150">
      <el-col :span="12" :offset="7">
        <span class="title1">正如，这束花一样</span>
      </el-col>
    </el-row>
    <div class="tupian">
      <img src="../assets/养护说明.png" alt />
      <img src="../assets/买前须知.jpg" alt />
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      products: [],
      tableData: [
        {
          date: "红色",
          name: "699",
          address: "8-10枝"
        },
        {
          date: "黄色",
          name: "699",
          address: "8-10枝"
        },
        {
          date: "粉色",
          name: "699",
          address: "8-10枝"
        }
      ],
      multipleSelection: []
    };
  },
  computed: {
    pId: {
      get() {
        return this.$store.state.productId;
      },
      set(v) {
        this.$store.state.productId = v;
      }
    },
    user: {
      get() {
        return this.$store.state.user;
      },
      set(v) {
        this.$store.state.user = v;
      }
    }
  },
  methods: {
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getPic(pic) {
      let path = "http://localhost:3000/images/" + pic;
      console.log(path);
      return path;
    },
    open1() {
      this.$axios
        .post("http://localhost:3000/shopping/addProduct/" + this.user[0].userId, {
          productId: this.pId
        })
        .then(res => {
          if(res.data.data==-1){
              this.$message({
            showClose: true,
            message: "您已加入过购物车了哦！",
            type: "success",
            center: true
          });
          }else{
              this.$message({
            showClose: true,
            message: "成功加入购物车！",
            type: "success",
            center: true
          });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    open2() {
      this.$axios
        .post("http://localhost:3000/collection/addProduct/" + this.user[0].userId, {
          productId: this.pId
        })
        .then(res => {
          if(res.data.data==-1){
              this.$message({
            showClose: true,
            message: "您收藏过了哦！",
            type: "success",
            center: true
          });
          }else{
              this.$message({
            showClose: true,
            message: "收藏成功！",
            type: "success",
            center: true
          });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
  },
  created() {
    this.$store.state.navIndex = "0";

    this.$axios
      .get("http://localhost:3000/product/productDetail/" + this.pId)
      .then(res => {
        console.log(res.data.data);
        this.products.push(res.data.data);
        console.log(this.products[0]);
      })
      .catch(err => {
        console.log(err);
      });
  }
};
</script>
<style>
.xiangqingye .element.style {
  padding-left: 2px;
  padding-right: 2px;
}
.xiangqingye .btn {
  width: 300px;
  height: 100px;
}
/* .btn[data-v-63ae9146] {
    background-color: white;
  } */
.xiangqingye .el-main[data-v-63ae9146] {
  text-align: left;
  line-height: 50px;
}
.xiangqingye .tu {
  height: 500px;
  width: 100%;
}
.xiangqingye .title {
  font-size: 50px;
}
.xiangqingye .title1 {
  font-size: 20px;
}
.xiangqingye .tupian {
  text-align: center;
  width: 100%;
}
</style>

<style lang="scss" scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #d3dce6;
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.el-header,
.el-footer {
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  color: #333;
  text-align: left;
  line-height: 50px;
}
.el-col > .font {
  position: relative;
  top: 30px;
}
//   body > .el-container {
//     margin-bottom: 40px;
//   }

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
.xiangqingye {
  width: 70%;
  height: 100%;
  margin: 0 auto;
}
.box {
  border: 1px #ffd04b solid;
}
.imgbox {
  height: 300px;
  width: 100%;
}
.btn {
  background-color: #e7cb68;
  width: 100%;
  height: 50px;
}

@media screen and (max-width: 1200px) {
  .el-aside {
    display: none;
  }
}
</style>